package licode.unisop.realm.application.uniclient;

import cn.hutool.core.bean.BeanUtil;
import licode.unisop.client.api.auth.SopUserAccessor;
import licode.unisop.client.info.SopAccountFind;
import licode.unisop.client.info.SopUserIdFind;
import licode.unisop.client.vo.SopUserBrief;
import licode.unisop.provider.info.UserIdInfo;
import licode.unisop.provider.vo.SiAccount;
import licode.unisop.provider.vo.SiUser;
import licode.unisop.provider.vo.SiUserBrief;
import licode.unisop.realm.application.executor.SiUserQueryExecutor;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author licode
 */
@Primary
@Component
public class SopUserAccessorImpl implements SopUserAccessor {
    @Resource
    private SiUserQueryExecutor siUserQueryExecutor;

    @Override
    public SopUserBrief getUserInfo(SopUserIdFind idFind) {
        SiUserBrief siUser = siUserQueryExecutor.lookupUserBriefById(UserIdInfo.builder()
                .realmId(idFind.getRealmId())
                .userId(idFind.getUserId())
                .build());
        return null == siUser ? null : BeanUtil.copyProperties(siUser, SopUserBrief.class);
    }

    @Override
    public SopUserBrief getUserInfo(SopAccountFind account) {
        SiUserBrief siUser = siUserQueryExecutor.lookupUserBriefByAccount(SiAccount.builder()
                .realmId(account.getRealmId())
                .category(account.getCategory())
                .account(account.getAccount())
                .data(account.getData())
                .build());
        return null == siUser ? null : BeanUtil.copyProperties(siUser, SopUserBrief.class);
    }

    @Override
    public void updateUserInfo(SopUserBrief userInfo) {

    }
}
